package com.situ.day3.homework;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {
	@Test
	public void test1() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串：");
		String str = scanner.next();// "12321"
		char[] array = str.toCharArray();
		boolean isHuiWen = true;// 初始认为这是一个回文
		for (int i = 0; i < array.length / 2; i++) {
			if (array[i] != array[array.length - i - 1]) {
				isHuiWen = false;// 不是回文
				break;// 直接退出循环，后面根本不需要判断
			}
		}
		if (isHuiWen) {// if (isHuiWen == true) {
			System.out.println("是回文");
		} else {
			System.out.println("不是回文");
		}
	}

	@Test
	public void test2() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串");
		String str = scanner.nextLine();
		char[] array = str.toCharArray();// r8ehre* 34h
		int numCount = 0;
		int charCount = 0;
		int blankCount = 0;
		int otherCount = 0;
		for (int i = 0; i < array.length; i++) {
			char ch = array[i];
			if ((ch >= 'a' && ch <= 'z') 
					|| (ch >= 'A' && ch <= 'Z')) {
				charCount++;
			} else if (ch >= '0' && ch <= '9') {
				numCount++;
			} else if (ch == ' ') {
				blankCount++;
			} else {
				otherCount++;
			}
		}
		
		System.out.println("字符串中数字出现的个数为：" + numCount);
		System.out.println("字符串中字母出现的个数为：" + charCount);
		System.out.println("字符串中空格出现的个数为：" + blankCount);
		System.out.println("字符串中其他出现的个数为：" + otherCount);
	}
	
	@Test
	public void test3() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入第一个数：");
		int x = scanner.nextInt();
		System.out.println("请输入第二个数：");
		int y = scanner.nextInt();
		System.out.println("请输入第三个数：");
		int z = scanner.nextInt();
		//首先保证x是存放最小的值
		if (x > y) {
			int temp = x;
			x = y;
			y = temp;
		}
		if (x > z) {
			int temp = x;
			x = z;
			z = temp;
		}
		//到这一步，x分别和y、z比较，x现在存放的是最小值
		//接下来只要比较y和z谁大谁小就可以了
		if (y > z) {
			int temp = y;
			y = z;
			z = temp;
		}
		System.out.println("x: " + x);
		System.out.println("y: " + y);
		System.out.println("z: " + z);
	}
	
	
	

}
